
use "D:\Dropbox\Work - RA\D02 - REV and MOM relationship\A01_Panel_data_WITH_US.dta", replace
cd "D:\Dropbox\Work - RA\! (2025.03.03) Final replication code for RFS"
gen con=1


* REV is multiplied by -1 (sign flip) to indicate reversal "profit";
replace rev=rev*(-1)
replace mktvol_mkt_dret=mktvol_ewret if missing(mktvol_mkt_dret)


* Require IO (from year 2000)
keep if year>=2000
count

* Select country-months with firms with sufficient number of IO information
keep if num_country>=125


* Compute 1-IO (EW)
sum io_VW, det
capture drop one_minus_io_VW
gen one_minus_io_VW=1-io_VW
sum one_minus_io_VW

* Compute 1-IO (EW)
sum io_EW, det
capture drop one_minus_io_EW
gen one_minus_io_EW=1-io_EW
sum one_minus_io_EW

* Sort by {one_minus_io_VW} for all countries
capture drop noise_VW noise_VW_by_dev
sort year month	Dev_dummy
astile noise_VW=one_minus_io_VW , n(2) by(year month)
astile noise_VW_by_dev=one_minus_io_VW , n(2) by(year month Dev_dummy)


* Sort by {one_minus_io_EW} for all countries
capture drop noise_EW noise_EW_by_dev
sort year month	Dev_dummy
astile noise_EW=one_minus_io_EW , n(2) by(year month)
astile noise_EW_by_dev=one_minus_io_EW , n(2) by(year month Dev_dummy)


* Drop without noise_EW_by_dev
sum num_country, det
drop if missing(noise_EW_by_dev)


* Momentum / Reversal profite by 1-IO median

	* 1-IO (EW) by each group 
	sort Dev_dummy noise_EW_by_dev
	by Dev_dummy noise_EW_by_dev: sum one_minus_io_EW, det
	sort noise_EW_by_dev
	by noise_EW_by_dev: sum one_minus_io_EW, det

	* Developing (EW)
	eststo clear
	estpost ttest mom rev if Dev_dummy==0, by(noise_EW_by_dev)	
	esttab . using "Result_Table_6_A.csv", replace cells("N_1 N_2 mu_1 mu_2 t p") title("Developing countries")

	* Developed (EW)
	eststo clear 
	estpost ttest mom rev if Dev_dummy==1, by(noise_EW_by_dev)
	esttab . using "Result_Table_6_A.csv", append cells("N_1 N_2 mu_1 mu_2 t p") title("Developed countries")

	* Aggregate (EW)
	eststo clear 
	estpost ttest mom rev, by(noise_EW_by_dev)
	esttab . using "Result_Table_6_A.csv", append cells("N_1 N_2 mu_1 mu_2 t p") title("Aggregate")
